Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-764: new sentry logger #77

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

jomcarvajal
Copy link
Contributor

Card: https://openstax.atlassian.net/browse/CORE-764

First step: implement a logger that logs to the sentry breadcrumbs

@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ToggleButtonGroup matches snapshot with selectionMode #selectionMode 1`] = `
exports[`ToggleButtonGroup matches snapshot with selectionMode multiple 1`] = `
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix test descriptions

@@ -30,7 +30,8 @@ describe('ToggleButtonGroup', () => {
selectionMode
${'multiple'}
${'single'}
`(`matches snapshot with selectionMode #selectionMode`, ({selectionMode}) => {
${undefined}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covering line 20 of ToggleButtonGroup file.

@Dantemss Dantemss requested review from a team and jmonteroa05 and removed request for a team March 20, 2025 15:08
* More info: https://develop.sentry.dev/sdk/data-model/event-payloads/breadcrumbs/
*/

const serializeLevel = (level: Level): string =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could make this

Suggested change
const serializeLevel = (level: Level): string =>
const serializeLevel = (level: Level): SeverityLevel =>

return {
type: (type?? '') as string,
level: serializeLevel(level) as SeverityLevel,
"event_id": (event_id ?? '') as string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see this as an allowed parameters, is there other documentation that needs to be linked to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I took it from code. addBreadcrumb is expecting:

  type?: string;
  level?: Severity | SeverityLevel;
  event_id?: string;
  category?: string;
  message?: string;
  data?: {
      [key: string]: any;
  };
  timestamp?: number;

That is why I leave it there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it to keep it faithful to the documentation

type: (type?? '') as string,
level: serializeLevel(level) as SeverityLevel,
"event_id": (event_id ?? '') as string,
category: (category ?? '') as string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should do typeof checks on all of these instead of just casting them, the input interface would allow them to be arrays or objects which wouldn't work

timestamp?: number;
data?: { [key: string]: any };
} => {
const { type, event_id, category, message, timestamp, data } = breadcrumb;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could take a rest parameter here and append the remaining stuff in the event to the data key. you'll have to do something to flatten it though because i think it only supports key value pairs. maybe something like this https://stackoverflow.com/a/74769002/14809536

value && typeof value === typeValue ? value : defaultValue
;

const flattenObj = (obj: { [x: string]: any; }) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when copying red-code from stack overflow i like to put a link to the SO answer in a comment above the function

const { type, category, message, timestamp, ...rest } = breadcrumb;

return {
type: checkTypeOf(type, 'string', ''),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like breadcrumb type means stuff https://develop.sentry.dev/sdk/data-model/event-payloads/breadcrumbs/#breadcrumb-types and each one has a different schema for the other properties. based on what we have here so far, we may just want to submit only 'default' breadcrumbs and worry about adding support for other types later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading type 'default' , I see that is expecting data as undefined. We need a breadcrumb with category="log" and avoid passing type in order to send a data key. Thanks for highlighting this info to me.

Comment on lines 11 to 17
const checkTypeOf = (
value: JsonCompatibleStruct | JsonCompatibleValue | JsonCompatibleArray,
typeValue: string,
defaultValue: any,
) =>
value && typeof value === typeValue ? value : defaultValue
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to work fine for what you're doing, but it doesn't have a type safe response. a generic helper would look like this although its of course much simpler if you make it string specific. you're also not really saving yourself that many characters where you're calling this, you could just put all the ternaries inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants